#ifndef DRAW_H
#define DRAW_H

#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <vector>
#include <memory>
#include "config.h"
#include "item.h"

// Forward declaration
struct Config;

// RAII wrapper for Xft Font (auto-cleanup)
struct Fnt
{
    Display *dpy;
    XftFont *xfont;
    FcPattern *pattern;
    unsigned int h; // Font height (ascent + descent)

    ~Fnt();
};

// Drawing context (manages X11 resources)
struct Drw
{
    Display *dpy;
    int screen;
    Window root;
    Drawable drawable;                        // Offscreen buffer (double-buffering)
    GC gc;                                    // X11 Graphics Context
    unsigned int w, h;                        // Drawable dimensions (pixels)
    std::vector<std::unique_ptr<Fnt>> fonts;  // Loaded fonts
    XftColor scheme[(size_t)Scheme::LAST][2]; // Cached colors

    Drw(Display *d, int s, Window r, unsigned int w_, unsigned int h_);
    ~Drw();

    void resize(unsigned int w_, unsigned int h_);
    bool loadFonts(const std::vector<std::string> &fontNames);
    void allocColors(const Config &cfg);
    unsigned int getTextWidth(const char *text);
    void drawItem(Item *item, int x, int y, int w);
    void drawMenu();
};

#endif // DRAW_H
